global loader
extern kmain

; All the multiboot stuff:
; http://www.gnu.org/software/grub/manual/multiboot/multiboot.html
MODULEALIGN equ   1 << 0
MEMINFO     equ   1 << 1
FLAGS       equ   (MODULEALIGN | MEMINFO)
MAGIC       equ   0x1BADB002
CHECKSUM    equ   -(MAGIC + FLAGS)

section .text
align 4
; This HAS to be in the first 8192 bytes of the os image
; magic, flags, and checksum are required.  If we set flags[16]
; then we can also set address fields of the multiboot header.
; Apparently if we use ELF format for our kernel than its all good,
; otherwise we'll have to set this.
; If we set flashs[2] then that is the graphics fields.  We can
; use these to get GRUB to switch into this mode for us.
MultiBootHeader:
   dd MAGIC
   dd FLAGS
   dd CHECKSUM

; A stack of 16k...
STACKSIZE equ 0x4000

loader:
   mov esp, stack + STACKSIZE

   ; This should be 0x2BADB002, if not then we can't trust
   ; whatever is in ebx and should just die.
   push rax
   push rbx

   call kmain

   cli

hang:
   hlt
   jmp hang

section .bss
align 4
stack:
   resb STACKSIZE

